// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    src: [{
        id: 1,
        img: '../../image/aaaa.jpg'
      },
      {
        id: 2,
        img: '../../image/aaaa.jpg'
      },
      {
        id: 3,
        img: '../../image/aaaa.jpg'
      },
    ],
    res: [{
        id: 1,
        type: "khsw",
        img: '../../img/khs.png'
      },
      {
        id: 2,
        type: "yhlj",
        img: '../../img/yhlj.png'
      },
      {
        id: 3,
        type: "cylj",
        img: '../../img/cy.png'
      },
      {
        id: 4,
        type: "qtlj",
        img: '../../img/qt.png'
      }
    ],
    // 搜索关键字
    searchKey: '',
    isShow: false,
    garbage: {},
    elements: [{
        title: '语言识别',
        name: 'search',
        login: true,
        img: '../../image/4.png'
      },
      {
        title: '拍照识别',
        name: 'photo',
        login: true,
        img: '../../image/3.png'
      },
      {
        title: '站点定位',
        name: 'gps',
        login: true,
        img: '../../image/2.png'
      },
      {
        title: '图谱下载',
        name: 'download',
        login: true,
        img: '../../image/1.png'
      }
    ]
  },

  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },

  // 子组件触发父组件
  cardClick(e) {
    let index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: `/subA/detail/detail?index=${index}`
    })
  },
  onChange(e) {
    this.setData({
      value: e.detail,
    });
  },
  onSearch(e) {
    let searVal = e.detail
    const list = [{
      name: '苹果',
      category: '厨余垃圾'
    }, {
      name: '电池',
      category: '有害垃圾'
    }, {
      name: '瓶子',
      category: '可回收物'
    }, {
      name: '毛发',
      category: '其他垃圾'
    }]
    let res = []
    res = list.filter(item => {
      return item.name == searVal
    })
    // console.log(res[0]);
    this.setData({
      isShow: true,
      garbage: res[0]
    })

  },
  closeDialog() {
    this.setData({
      searchKey: '',
      isShow: false
    })
  },
  goMenu(e) {
    let {
      login
    } = e.currentTarget.dataset.item
    console.log(login);
    // if (login) {
    //   let userInfo = wx.getStorageSync('mini-userInfo')
    //   if (!userInfo) {
    //     app.$util.errorToShow("请先登录", () => {
    //       app.$util.switchTabTo("/pages/user/user")
    //     })
    //     return
    //   }
    // }
    let url = e.currentTarget.dataset.url
    console.log(url);
    wx.navigateTo({
      url: url
    })
  },
})